<template>
  <div class="student-search">
    <h2>滨海校区学生查询</h2>
    <div class="search-box">
      <input 
        v-model="studentId" 
        placeholder="请输入学号"
        @keyup.enter="searchStudent"
      />
      <button @click="searchStudent">查询</button>
    </div>
    <div v-if="studentInfo || studentId === ''" class="student-info">
      <template v-if="studentInfo">
        <p>姓名: {{ studentInfo.name }}</p>
        <p>学号: {{ studentInfo.id }}</p>
        <p>年级: {{ studentInfo.grade }}</p>
      </template>
      <template v-else>
        <h3>所有学生数据</h3>
        <div v-for="student in students" :key="student.id" class="student-item">
          <p>姓名: {{ student.name }}</p>
          <p>学号: {{ student.id }}</p>
          <p>年级: {{ student.grade }}</p>
          <hr>
        </div>
      </template>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CampusBinhai',
  data() {
    return {
      studentId: '',
      studentInfo: null,
      students: [
        { id: '2021001', name: '张三', grade: '一年级' },
        { id: '2021002', name: '李四', grade: '二年级' },
        { id: '2021003', name: '王五', grade: '三年级' }
      ]
    }
  },
  methods: {
    searchStudent() {
      this.studentInfo = this.students.find(s => s.id === this.studentId) || null
    }
  }
}
</script>

<style scoped>
.student-search {
  padding: 20px;
  max-width: 500px;
  margin: 0 auto;
}
.search-box {
  display: flex;
  gap: 10px;
  margin: 20px 0;
}
.search-box input {
  flex: 1;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
}
.search-box button {
  padding: 8px 16px;
  background-color: #42b983;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.student-info {
  margin-top: 20px;
  padding: 15px;
  border: 1px solid #eee;
  border-radius: 4px;
}
</style>